package spring.mvc.controller;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.handler.SimpleServletHandlerAdapter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller("/servletController")
public class My_05_HttpServlet extends HttpServlet {

    // 即使使用了 @EnableWebMvc，Spring MVC 默认也不会给你注册 SimpleServletHandlerAdapter这个适配器(其余三个都给注册了)，
    // 因此此处我们自己注册一下即可，让支持 Servlet 这种 Handler 的方式
    @Bean
    public SimpleServletHandlerAdapter simpleServletHandlerAdapter() {
        return new SimpleServletHandlerAdapter();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("this my servlet controller");
    }
}
